package com.openxt.nbzj.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.openxt.nbzj.R;
import com.openxt.nbzj.activity.WebViewActivity;
import com.openxt.nbzj.model.ConfigModel;

import org.xutils.x;

import butterknife.BindView;
import butterknife.ButterKnife;
import qs.openxt.libs.util.ActivityUtil;
import qs.openxt.libs.util.StringUtil;
import qs.openxt.libs.util.Utils;

/**
 * Created by 颖杰_2 on 2016/7/10.
 */
public class BigImgFragment extends OpenxtFragment implements View.OnClickListener {
    @BindView(R.id.big_img)
    ImageView big_img;
    @BindView(R.id.TITLE)
    TextView TITLE;

    Context mContext;

    JSONObject mData = null;
    public void setData(JSONObject mData) {
        this.mData = mData;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.news_work_big_item, container, false);
        ButterKnife.bind(this, view);
        view.setOnClickListener(this);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mContext = getActivity();

        String url = mData.getString("img");
        if(!StringUtil.isNull(url))
            x.image().bind(big_img, mData.getString("img"));
        TITLE.setText(mData.getString("title"));
    }

    @Override
    public void refresh() {

    }

    @Override
    public void willBeDisplayed() {

    }

    @Override
    public void onClick(View v) {
        if(!ActivityUtil.isNetworkAvailable(mContext)){
            showMsg("无网络，请先查看网络是否正常打开");
            return;
        }
        Utils.setLocalStorage(mContext, ConfigModel.NATIVE_PAGENAME, getActionUrl());
        Bundle bundle = new Bundle();
        bundle.putString("url", ConfigModel.ROOTPATH + mData.getString("RedirectURL"));
        toActivity(WebViewActivity.class, bundle, false);
    }
}

